﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using SoftwareConsulting.BI11.Studio.UI.ProjectExplorer;

namespace SoftwareConsulting.BI11.Studio
{
    static class Program
    {
        /// <summary>
        /// Обработка необработанных исключений
        /// </summary>
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
#if DEBUG
#else
            string fatalstring = string.Empty;            
            if (args.IsTerminating)
            {
                fatalstring = char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + Resources.RS_FATAL;
            }
            string fname = Path.GetTempPath() + Resources.RS_UNHANDLED_LOGFILE;
            string logstring = Resources.RS_UNHANDLED_EXCEPTION + char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + args.ExceptionObject.ToString() + fatalstring + char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(10) + char.ConvertFromUtf32(13) + fname;
            MessageBox.Show(logstring, Resources.RS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            using (StreamWriter writer = File.CreateText(fname))
            {
                writer.WriteLine(logstring);
                writer.Close();
            }
#endif
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ProjectExplorerForm pef = new ProjectExplorerForm();
            if (!pef.FailedLogOn && !pef.CanceledLogOn)
            {
                Application.Run(pef);
            }
        }
    }
}
